struct Solution;

impl Solution {
    pub fn max_satisfied(customers: Vec<i32>, grumpy: Vec<i32>, x: i32) -> i32 {
        let mut win = 0;
        let mut sat = 0;
        let x = x as usize;
        let mut max_win = 0;

        for (index, (val, customer)) in grumpy.iter().zip(customers.iter()).enumerate() {
            if *val == 0 {
                sat += *customer;
            } else {
                win += *customer;
            }
            if index >= x && grumpy[index - x] == 1 {
                win -= customers[index - x];
            }
            max_win = i32::max(max_win, win);
        }
        sat + max_win
    }
}

fn main() {
    let customers = vec![1, 0, 1, 2, 1, 1, 7, 5];
    let grumpy = vec![0, 1, 0, 1, 0, 1, 0, 1];
    let x = 3;
    let val = Solution::max_satisfied(customers, grumpy, x);
    assert_eq!(val, 16);

}
